/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gblend.db;

import org.jdesktop.application.Task;
import gblend.GBlendApp;

/**
 *
 * @author cjjin
 */
public class AddDBTask extends Task<Void, DatabaseInfo> {

    private DatabaseInfo databaseInfo;
    private LoadSchema load = new LoadSchema();

    public AddDBTask(

        GBlendApp application,
        DatabaseInfo db)
        {
            super(application);
            this.databaseInfo = db;
        }

    public AddDBTask(DatabaseInfo databaseInfo)
    {
        super(GBlendApp.getApplication());
        this.databaseInfo = databaseInfo;
      
    }

    @Override
    protected void failed(Throwable arg0) {
        super.failed(arg0);
        setMessage("Database Creation Failed: " + databaseInfo.getDbName());
        System.out.println(this.getMessage());
    }

    @Override
    protected void succeeded(Void arg0) {
        setMessage("Database: " + databaseInfo.getDbName() + "  created successfully...");
        System.out.println(this.getMessage());
    }

    @Override
    protected Void doInBackground() throws Exception
    {

        setMessage("Adding Database: " + databaseInfo.getDbName());
        System.out.println(this.getMessage());
        load.loadDB(databaseInfo,GBlendApp.getDbManager().getView().getTree());
         
        GBlendApp.getDbManager().addDatabase(databaseInfo);
        
        return null;
    }

    public DatabaseInfo getDatabaseInfo()
    {
        return databaseInfo;
    }

    public void setDatabaseInfo(DatabaseInfo databaseInfo)
    {
        this.databaseInfo = databaseInfo;
    }
}
